using UnityEngine;
using System.Collections;

public class CameraCtrl : MonoBehaviour {
	
	private CameraFollowState m_camFollowState;
	
	private Transform target;
	
	public void SmoothFollow(){
		m_camFollowState = CameraFollowState.smoothfollow;
	}
	public void Follow(){
		m_camFollowState = CameraFollowState.follow;
	}
	
	void Start(){
		if(!target){
			target = GameObject.FindGameObjectWithTag("Player").transform;
		}
	}
	void LateUpdate(){
		switch(m_camFollowState){
		case CameraFollowState.follow:
			//Follow
			transform.position = new Vector3(target.position.x,target.position.y,-10);
			break;
		case CameraFollowState.smoothfollow:
			//Interpolation for Camera Follow Target(Player)
			transform.position = Vector3.MoveTowards(transform.position,new Vector3(target.position.x,target.position.y,-10),Time.deltaTime*50);
			
			//Arrive - Change SmoothFollow To Follow
			if(Vector3.Distance(transform.position,new Vector3(target.position.x,target.position.y,-10))<0.2f){
				Follow();
			}
			break;
		}
	}
}
public enum CameraFollowState{
	follow,//General Case
	smoothfollow//for portal
}
